﻿using System;
using System.Collections;

namespace ConsoleApp16
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("查找集合中是否含有 abc 元素");
            ArrayList list = new ArrayList() { "aaa", "bbb", "abc", 123, 456 };
            int index = list.IndexOf("abc");
            if (index != -1)
            {
                Console.WriteLine("集合中存在 abc 元素！");
            }
            else
            {
                Console.WriteLine("集合中不存在 abc 元素！");
            }
            Console.WriteLine("将集合中元素下标是偶数的元素添加到另一个集合中");
            ArrayList newList = new ArrayList();
            for (int i = 0; i < list.Count; i = i + 2)
            {
                newList.Add(list[i]);
            }
            foreach (var a in newList)
            {
                Console.WriteLine(a);
            }
            Console.WriteLine("在集合中第一个元素的后面任意插入 3 个元素");
            ArrayList list2 = new ArrayList() { "aaa", "bbb", "abc", 123, 456 };
            ArrayList insert = new ArrayList() { "A", "B", "C" };
            list2.InsertRange(1, insert);
            foreach (var v in list2)
            {
                Console.WriteLine(v);
            }
            Console.WriteLine("将集合中的元素使用 Sort 方法排序后输出");
            ArrayList list3 = new ArrayList() { "aaa", "bbb", "abc" };
            list3.Sort();
            foreach (var v in list3)
            {
                Console.WriteLine(v);
            }
            Console.WriteLine("使用ICompare的方式来排序输出string");

            ArrayList arrayList = new ArrayList() {"fdf","fgh","nsd",264,452};

            foreach (var c in arrayList)
            {
                Console.WriteLine(c);
            }
            MyCompare myCompare = new MyCompare();
            arrayList.Sort(myCompare);
            Console.WriteLine();
            foreach (var c in arrayList)
            {
                Console.WriteLine(c);
            }
        }


    }


}

